﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luxury_car_sales_system
{
    public partial class Goods_maintain : Form
    {
        public Goods_maintain()
        {
            InitializeComponent();
        }

        private void Goods_maintain_Load(object sender, EventArgs e)
        {
            string sql = "select * from Goods";
            DBHelper.dataSet.Tables.Clear();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBHelper.getDataTable(sql);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sql = "select * from Goods";
            DBHelper.dataSet.Tables.Clear();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBHelper.getDataTable(sql);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = string.Format("select * from Goods where GoodsID='{0}' or GoodsName='{1}'",textBox1.Text,textBox2.Text);
            DBHelper.dataSet.Tables.Clear();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBHelper.getDataTable(sql);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Goods_maintain2 Gm2 = new Goods_maintain2();
            Gm2.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string index = dataGridView1.SelectedCells[0].Value.ToString();
            string sql = string.Format("delete from Goods where GoodsID={0}", index);
            bool b = DBHelper.ExcuteNonQuery(sql);
            if (b == true)
            {
                MessageBox.Show("删除成功");
                string sql1 = "select * from Goods";
                DBHelper.dataSet.Tables.Clear();
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = DBHelper.getDataTable(sql1);
            }
            else if (b == false)
            {
                MessageBox.Show("删除失败");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
